home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / program / vlibbc.zip / VLIBDEMO.C < prev    next >
C/C++ Source or Header  |  1992-02-04  |  25KB  |  941 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM:    Vlibdemo.exe
  4.  
  5.     PURPOSE:    To demostrate the usage of Visualib functions.
  6.         
  7.     PROVIDER:    Visual Tech, Co.
  8.         
  9.     DATE:    January, 1992
  10.  
  11.     FUNCTIONS:
  12.  
  13.     WinMain() - calls initialization function, processes message loop
  14.     InitApplication() - initializes window data and registers window
  15.     InitInstance() - saves instance handle and creates main window
  16.     MainWndProc() - processes messages
  17.     About() - processes messages for "About" dialog box
  18.  
  19.     COMMENTS:
  20.  
  21. ****************************************************************************/
  22.  
  23. #include "windows.h"
  24. #include "vlibdemo.h"
  25. #include "visualib.h"
  26.  
  27. HANDLE hInst;
  28. HVIEW    viewer21, viewer22, viewer31, viewer32, viewer33, viewer34, viewer35;
  29. int demo_flag, demo_type, demo_item;
  30.  
  31. /****************************************************************************
  32.  
  33.     FUNCTION: WinMain (HANDLE, HANDLE, LPSTR, int)
  34.  
  35.     PURPOSE: calls initialization function, processes message loop
  36.  
  37.     COMMENTS:
  38.  
  39.         Windows recognizes this function by name as the initial entry point 
  40.         for the program.  This function calls the application initialization 
  41.         routine, if no other instance of the program is running, and always 
  42.         calls the instance initialization routine.  It then executes a message
  43.         retrieval and dispatch loop that is the top-level control structure 
  44.         for the remainder of execution.  The loop is terminated when a WM_QUIT
  45.         message is received, at which time this function exits the application
  46.         instance by returning the value passed by PostQuitMessage().
  47.  
  48.         If this function must abort before entering the message loop, it 
  49.         returns the conventional value NULL.  
  50.  
  51. ****************************************************************************/
  52.  
  53. int PASCAL WinMain (hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  54. HANDLE hInstance;
  55. HANDLE hPrevInstance;
  56. LPSTR lpCmdLine;
  57. int nCmdShow;
  58. {
  59.     MSG msg;
  60.  
  61.     if (!hPrevInstance)
  62.     if (!InitApplication (hInstance))
  63.         return (FALSE);
  64.  
  65.     if (!InitInstance (hInstance, nCmdShow))
  66.         return (FALSE);
  67.  
  68.     while (GetMessage (&msg, NULL, NULL, NULL))    {
  69.     TranslateMessage (&msg);
  70.     DispatchMessage (&msg);
  71.     }
  72.     return (msg.wParam);
  73. }
  74.  
  75.  
  76. /****************************************************************************
  77.  
  78.     FUNCTION: InitApplication (HANDLE)
  79.  
  80.     PURPOSE: Initializes window data and registers window class
  81.  
  82.     COMMENTS:
  83.  
  84.         This function is called at initialization time only if no other 
  85.         instances of the application are running.  This function performs 
  86.         initialization tasks that can be done once for any number of running 
  87.         instances.  
  88.  
  89.         In this case, we initialize a window class by filling out a data 
  90.         structure of type WNDCLASS and calling the Windows RegisterClass() 
  91.         function.  Since all instances of this application use the same window
  92.         class, we only need to do this when the first instance is initialized.
  93.  
  94. ****************************************************************************/
  95.  
  96. BOOL InitApplication (hInstance)
  97. HANDLE hInstance;
  98. {
  99.     WNDCLASS  wc;
  100.     
  101.     if (InitialGraphics2D (0, 0, 0)) {
  102.     return (FALSE);
  103.     }
  104.     viewer21 = CreateViewer2D ("2D Objects", 10, 10, 100, 100);
  105.     SetWindow2D (viewer21, -10, -10, 10, 10);
  106.     viewer22 = CreateViewer2D ("U.S. Flag", 10, 10, 400, 217);
  107.     SetWindow2D (viewer22, 0, 0, 1, (float) (13.0 / 24.0));
  108.     if (InitialGraphics3D (0, 0, 0)) {
  109.     return (FALSE);
  110.     }
  111.     viewer31 = CreateViewer3D ("View Motion", 120, 10, 100, 100);
  112.     SetView3D (viewer31, 100, 100, 100, 0, 0, 0, 0);
  113.     SetPerspective3D (viewer31, 45, 1, 1, 1000);
  114.     viewer32 = CreateViewer3D ("Object Rotation", 230, 10, 100, 100);
  115.     SetView3D (viewer32, 100, 100, 100, 0, 0, 0, 0);
  116.     SetPerspective3D (viewer32, 45, 1, 1, 1000);
  117.  
  118.     viewer33 = CreateViewer3D ("View Zoom", 230, 130, 100, 100);
  119.     SetPolarView3D (viewer33, 1, 1, 0, 20, 75, 45, 0);
  120.     SetPerspective3D (viewer33, 90, 1, 1, 1000);
  121.  
  122.     viewer34 = CreateViewer3D ("Ortho Project", 120, 130, 100, 100);
  123.     SetPolarView3D (viewer34, 1, 1, 0, 10, 45, 45, 0);
  124.     SetOrthogonal3D (viewer34, -10, 10, -10, 10, 1, 100);
  125.  
  126.     viewer35 = CreateViewer3D ("Depth Clipping", 10, 130, 100, 100);
  127.     SetPolarView3D (viewer35, 1, 1, 0, 20, 75, 45, 0);
  128.     SetPerspective3D (viewer35, 90, 1, 1, 80);
  129.     
  130.     demo_flag = 1;
  131.     demo_item = 1;
  132.     demo_type = 1;
  133.     
  134.     wc.style = NULL;
  135.     wc.lpfnWndProc = MainWndProc;
  136.     wc.cbClsExtra = 0;
  137.     wc.cbWndExtra = 0;
  138.     wc.hInstance = hInstance;
  139.     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  140.     wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  141.     wc.hbrBackground = GetStockObject (WHITE_BRUSH); 
  142.     wc.lpszMenuName =  "VlibDemo";
  143.     wc.lpszClassName = "VlibDemoClass";
  144.  
  145.     return (RegisterClass (&wc));
  146.  
  147. }
  148.  
  149.  
  150. /****************************************************************************
  151.  
  152.     FUNCTION:  InitInstance (HANDLE, int)
  153.  
  154.     PURPOSE:  Saves instance handle and creates main window
  155.  
  156.     COMMENTS:
  157.  
  158.         This function is called at initialization time for every instance of 
  159.         this application.  This function performs initialization tasks that 
  160.         cannot be shared by multiple instances.  
  161.  
  162.         In this case, we save the instance handle in a static variable and 
  163.         create and display the main program window.  
  164.         
  165. ****************************************************************************/
  166.  
  167. BOOL InitInstance (hInstance, nCmdShow)
  168. HANDLE    hInstance;
  169. int    nCmdShow;
  170. {
  171.     HWND            hWnd;
  172.     int    sw, sh, ww, wh;
  173.  
  174.     sw = GetSystemMetrics (0);
  175.     sh = GetSystemMetrics (1);
  176.     hInst = hInstance;
  177.  
  178.     ww = (int) (sw * 0.666);
  179.     wh = (int) (sh * 0.666);
  180.     sw = (int) (sw * 0.167);
  181.     sh = (int) (sh * 0.167);
  182.     hWnd = CreateWindow ("VlibDemoClass",
  183.         "Visualib 1.0 (C) Demonstration",
  184.         WS_OVERLAPPEDWINDOW, sw, sh, ww, wh,
  185.         NULL, NULL, hInstance, NULL);
  186.  
  187.     if (!hWnd)
  188.         return (FALSE);
  189.  
  190.     ShowWindow (hWnd, nCmdShow);
  191.     UpdateWindow (hWnd);
  192.     
  193.     return (TRUE);
  194. }
  195.  
  196. HANDLE GetPrinterDC ()
  197. {
  198.     char    pPrintInfo[80];
  199.     LPSTR    lpTemp;
  200.     LPSTR    lpPrintType;
  201.     LPSTR    lpPrintDriver;
  202.     LPSTR    lpPrintPort;
  203.  
  204.     if (!GetProfileString ("windows", "Device", (LPSTR)"", pPrintInfo, 80))
  205.         return (NULL);
  206.     lpTemp = lpPrintType = pPrintInfo;
  207.     lpPrintDriver = lpPrintPort = 0;
  208.     while (*lpTemp) {
  209.         if (*lpTemp == ',') {
  210.             *lpTemp++ = 0;
  211.             while (*lpTemp == ' ')
  212.                 lpTemp = AnsiNext (lpTemp);
  213.             if (!lpPrintDriver)
  214.                 lpPrintDriver = lpTemp;
  215.             else {
  216.                 lpPrintPort = lpTemp;
  217.                 break;
  218.             }
  219.         }
  220.         else
  221.             lpTemp = AnsiNext (lpTemp);
  222.     }
  223.  
  224.     return (CreateDC (lpPrintDriver, lpPrintType, lpPrintPort, (LPSTR) NULL));
  225. }
  226.  
  227. void    USFlag (HDC hDC)
  228. {
  229.     short    i, j;
  230.     float    x1, y1, x2, y2;
  231.     float    width, height;
  232.  
  233.     width = 1;
  234.     height = (float) 13 / 24;
  235.     x1 = 0;
  236.     x2 = width;
  237.     y1 = 0;
  238.     y2 = height / 13;
  239.     BrushColor (hDC, WVRED);
  240.     PenColor (hDC, WVRED);
  241.     for (i = 0; i < 7; i ++) {
  242.     Rectangle2D (hDC, x1, y1, x2, y2);
  243.     y1 += height * 2 / 13;
  244.     y2 += height * 2 / 13;
  245.     }
  246.     
  247.     BrushColor (hDC, WVWHITE);
  248.     PenColor (hDC, WVWHITE);
  249.     y1 = height / 13;
  250.     y2 = height * 2 / 13 - 0.001;
  251.     for (i = 0; i < 6; i ++) {
  252.     Rectangle2D (hDC, x1, y1, x2, y2);
  253.     y1 += height * 2 / 13;
  254.     y2 += height * 2 / 13;
  255.     }
  256.  
  257.     BrushColor (hDC, WVBLUE);
  258.     PenColor (hDC, WVBLUE);
  259.     x2 = 10 * width / 24;
  260.     y1 = 6 * height / 13;
  261.     y2 = height;
  262.     Rectangle2D (hDC, x1, y1, x2, y2);
  263.  
  264.     BrushColor (hDC, WVWHITE);
  265.     PenColor (hDC, WVWHITE);
  266.     x2 /= 6;
  267.     x1 = 0.5 * x2;
  268.     y2 = height * 7 / 13 / 5;
  269.     for (i = 0; i < 6 ; i ++) {
  270.     y1 = height - 0.5 * y2;
  271.     for (j = 0; j < 5; j ++) {
  272.         NsideStar2D (hDC, x1, y1, 0.01, 5);
  273.         y1 -= y2;
  274.     }
  275.     x1 = x1 + x2;
  276.     }
  277.     x1 = x2;
  278.     for (i = 0; i < 5; i ++) {
  279.     y1 = height - y2;
  280.     for (j = 0; j < 4; j ++) {
  281.         NsideStar2D (hDC, x1, y1, 0.01, 5);
  282.         y1 -= y2;
  283.     }
  284.     x1 = x1 + x2;
  285.     }
  286. }
  287.  
  288. void    heart (HDC hdc)
  289. {
  290.     POINT2D p[20] = {{0, 0, 1}, {0.4, 0.8, 1}, {2, 1.4, 1},
  291.         {2.5, -1, 1}, {1, -2, 1}, {0, -3, 1},
  292.         {-1, -2, 1}, {-2.5, -1, 1}, {-2, 1.4, 1},
  293.         {-0.4, 0.8, 1}, {0, 0, 1}};
  294.         
  295.     float knot[20] = {0, 0, 0, 1, 2, 3, 3, 3,
  296.         4, 5, 6, 6, 6};
  297.     
  298.     NURBSCurve2D (hdc, p, 11, knot);
  299. }
  300.  
  301. void    logo (HDC hdc)
  302. {
  303.     MoveTo3D (hdc, 0, 0, 0);
  304.     LineTo3D (hdc, 1, 1, -1);
  305.     LineTo3D (hdc, 1, 1, 1);
  306.     LineTo3D (hdc, -1, -1, 1);
  307.     LineTo3D (hdc, -1, 1, -1);
  308.     LineTo3D (hdc, 1, -1, -1);
  309.     LineTo3D (hdc, 1, 1, 1);
  310.     LineTo3D (hdc, 1, -1, 1);
  311.     LineTo3D (hdc, -1, -1, 1);
  312.     LineTo3D (hdc, -1, 1, 1);
  313.     LineTo3D (hdc, -1, 1, -1);
  314.     LineTo3D (hdc, -1, -1, -1);
  315.     LineTo3D (hdc, 1, -1, -1);
  316.     LineTo3D (hdc, 1, 1, -1);
  317.     LineTo3D (hdc, -1, 1, 1);
  318.     LineTo3D (hdc, 0, 0, 0);
  319.     LineTo3D (hdc, 1, -1, 1);
  320.     LineTo3D (hdc, -1, -1, -1);
  321.     LineTo3D (hdc, 0, 0, 0);
  322. }
  323.  
  324. POINT3D circ[]= {
  325.     {1, 0, 0, 1},
  326.     {0.66666667, 0.57735027, 0.074074074, 0.66666667},
  327.     {0.16666667, 0.86602540, 0.148148148, 0.66666667},
  328.     {-0.5, 0.86602540, 0.33333333, 1}
  329. };
  330.  
  331. void    spring (HDC hdc)
  332. {
  333.     PushMatrix3D ();
  334.     BSplineCurve3D (hdc, circ, 4);
  335.     Translate3D (0, 0, 0.33333333);
  336.     Rotate3D (120, 'z');
  337.     BSplineCurve3D (hdc, circ, 4);
  338.     Translate3D (0, 0, 0.33333333);
  339.     Rotate3D (120, 'z');
  340.     BSplineCurve3D (hdc, circ, 4);
  341.     Translate3D (0, 0, 0.33333333);
  342.     Rotate3D (120, 'z');
  343.     BSplineCurve3D (hdc, circ, 4);
  344.     Translate3D (0, 0, 0.33333333);
  345.     Rotate3D (120, 'z');
  346.     BSplineCurve3D (hdc, circ, 4);
  347.     Translate3D (0, 0, 0.33333333);
  348.     Rotate3D (120, 'z');
  349.     BSplineCurve3D (hdc, circ, 4);
  350.     PopMatrix3D ();
  351. }
  352.  
  353.  
  354. POINT3D surf[16] = {
  355.     {-3, 0, 1, 1},
  356.     {1, 4, -1, 1},
  357.     {5, -2, 0, 1},
  358.     {8, 0, -2, 1},
  359.     {-2, 0, -3, 1},
  360.     {1, 4, 0, 1},
  361.     {5, -2, 1, 1},
  362.     {7, 0.6, 1, 1},
  363.     {-2, 2, 3, 1},
  364.     {1, 4, 3.5, 1},
  365.     {5, -2, 2, 1},
  366.     {7.5, 0.7, 3, 1},
  367.     {-2, 1, 6, 1},
  368.     {1, 4, 4, 1},
  369.     {5, -1, 4, 1},
  370.     {8, 0.5, 6.6, 1}
  371. };
  372.  
  373. float sknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  374. float tknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  375.  
  376. void    Object2D (HDC hdc)
  377. {
  378.     short    i;
  379.  
  380.     DisplayViewerFrame2D (hdc, viewer21, WVRED);
  381.     DisplayViewerName2D (hdc, viewer21, WVBLUE, 0);
  382.  
  383.     BeginDoubleBuffer2D (&hdc, viewer21);
  384.  
  385.     SelectViewer2D (viewer21);
  386.     PenColor (hdc, WVRED);
  387.  
  388.     for (i = 0; i < 5*demo_type; i ++) {
  389.     ClearViewer2D (hdc, viewer21, WVGRAY);
  390.     BrushColor (hdc, WVGREEN);
  391.     NsideFlower2D (hdc, 0, 0, 6, 4.5, 10);
  392.     BrushColor (hdc, WVRED);
  393.     NsideStar2D (hdc, 0, 0, 4, 5);
  394.     Rotate2D (6);
  395.     UpdateBuffer2D (hdc, viewer21);
  396.     }
  397.     for (i = 0; i < 5*demo_type; i ++) {
  398.     ClearViewer2D (hdc, viewer21, WVGRAY);
  399.     BrushColor (hdc, WVGREEN);
  400.     NsideFlower2D (hdc, 0, 0, 6, 4.5, 10);
  401.     BrushColor (hdc, WVRED);
  402.     NsideStar2D (hdc, 0, 0, 4, 5);
  403.     MoveViewer2D (viewer21, 0.25, 0);
  404.     UpdateBuffer2D (hdc, viewer21);
  405.     }
  406.  
  407.     for (i = 0; i < 5*demo_type; i ++) {
  408.     ClearViewer2D (hdc, viewer21, WVGRAY);
  409.     BrushColor (hdc, WVGREEN);
  410.     NsideFlower2D (hdc, 0, 0, 6, 4.5, 10);
  411.     BrushColor (hdc, WVRED);
  412.     NsideStar2D (hdc, 0, 0, 4, 5);
  413.     Scale2D (1.06, 1.06);
  414.     UpdateBuffer2D (hdc, viewer21);
  415.     }
  416.  
  417.     EndDoubleBuffer2D (&hdc, viewer21);
  418. }
  419.  
  420. void    ViewerMotion3D (HDC hdc)
  421. {
  422.     short    i;
  423.  
  424.     DisplayViewerFrame3D (hdc, viewer31, WVBLUE);
  425.     DisplayViewerName3D (hdc, viewer31, WVBLUE, 0);
  426.  
  427.     BeginDoubleBuffer3D (&hdc, viewer31);
  428.  
  429.     SelectViewer3D (viewer31);
  430.     BrushColor (hdc, WVRED);
  431.     for (i = 0; i < 5*demo_type; i ++) {
  432.     MoveViewer3D (viewer31, 0, 0, -10);
  433.     ClearViewer3D (hdc, viewer31, WVGRAY);
  434.     Box3D (hdc, -50, -50, 0, 50, 50, 50);
  435.     UpdateBuffer3D (hdc, viewer31);
  436.     }
  437.     BrushColor (hdc, WVGREEN);
  438.     for (i = 0; i < 5*demo_type; i ++) {
  439.     MoveViewer3D (viewer31, 0, 5, 0);
  440.     ClearViewer3D (hdc, viewer31, WVGRAY);
  441.     Box3D (hdc, -50, -50, 0, 50, 50, 50);
  442.     UpdateBuffer3D (hdc, viewer31);
  443.     }
  444.     BrushColor (hdc, WVBLUE);
  445.     for (i = 0; i < 5*demo_type; i ++) {
  446.     MoveViewer3D (viewer31, 5, 0, 0);
  447.     ClearViewer3D (hdc, viewer31, WVGRAY);
  448.     Cube3D (hdc, -50, -50, 0, 50, 50, 50);
  449.     UpdateBuffer3D (hdc, viewer31);
  450.     }
  451.     BrushColor (hdc, WVYELLOW);
  452.     for (i = 0; i < 5*demo_type; i ++) {
  453.     RotateWorld3D (viewer31, 0, 0, 6);
  454.     ClearViewer3D (hdc, viewer31, WVGRAY);
  455.     Cube3D (hdc, -50, -50, 0, 50, 50, 50);
  456.     UpdateBuffer3D (hdc, viewer31);
  457.     }
  458.     BrushColor (hdc, WVLIGHTBLUE);
  459.     for (i = 0; i < 5*demo_type; i ++) {
  460.     ClearViewer3D (hdc, viewer31, WVGRAY);
  461.     RotateWorld3D (viewer31, 0, 6, 0);
  462.     Cube3D (hdc, -50, -50, 0, 50, 50, 50);
  463.     UpdateBuffer3D (hdc, viewer31);
  464.     }
  465.     BrushColor (hdc, WVBROWN);
  466.     for (i = 0; i < 5*demo_type; i ++) {
  467.     ClearViewer3D (hdc, viewer31, WVGRAY);
  468.     RotateWorld3D (viewer31, 6, 0, 0);
  469.     Cube3D (hdc, -50, -50, 0, 50, 50, 50);
  470.     UpdateBuffer3D (hdc, viewer31);
  471.     }
  472.  
  473.     EndDoubleBuffer3D (&hdc, viewer31);
  474.  
  475. }
  476.  
  477. void    ObjectMotion3D (HDC hdc)
  478. {
  479.     short    i;
  480.     
  481.     DisplayViewerName3D (hdc, viewer32, WVBLUE, 0);
  482.     DisplayViewerFrame3D (hdc, viewer32, WVBLUE);
  483.  
  484.     BeginDoubleBuffer3D (&hdc, viewer32);
  485.     SelectViewer3D (viewer32);
  486.  
  487.     BrushColor (hdc, WVRED);
  488.     for (i = 0; i <= 5*demo_type; i ++) {
  489.     ClearViewer3D (hdc, viewer32, WVGRAY);
  490.     Cylinder3D (hdc, 0, 0, 0, 30, 50);
  491.     Rotate3D (3, 'z');
  492.     Rotate3D (6, 'x');
  493.     Rotate3D (3, 'y');
  494.     UpdateBuffer3D (hdc, viewer32);
  495.     }
  496.     EndDoubleBuffer3D (&hdc, viewer32);
  497. }
  498.  
  499. void    ViewerZoom3D (HDC hdc)
  500. {
  501.     short    i;
  502.  
  503.     DisplayViewerFrame3D (hdc, viewer33, WVRED);
  504.     DisplayViewerName3D (hdc, viewer33, WVBLUE, 0);
  505.  
  506.     BeginDoubleBuffer3D (&hdc, viewer33);
  507.     SelectViewer3D (viewer33);
  508.  
  509.     BrushColor (hdc, WVGREEN);
  510.     for (i = 0; i < 5*demo_type; i ++) {
  511.     ClearViewer3D (hdc, viewer33, WVGRAY);
  512.     MarkPosition3D (hdc, 0, 0, 0, 5);
  513.     Cone3D (hdc, 0, 0, 0, 3, 10);
  514.     ZoomViewer3D (viewer33, 1.05);
  515.     UpdateBuffer3D (hdc, viewer33);
  516.     }
  517.     EndDoubleBuffer3D (&hdc, viewer33);
  518. }
  519.  
  520. void    OrthoProject3D (HDC hdc)
  521. {
  522.     short    i;
  523.  
  524.     DisplayViewerFrame3D (hdc, viewer34, WVRED);
  525.     DisplayViewerName3D (hdc, viewer34, WVBLUE, 0);
  526.     SelectViewer3D (viewer34);
  527.     BrushColor (hdc, WVGREEN);
  528.     Sphere3D (hdc, 3, -1, -4, 3, 20, 10);
  529. }
  530.  
  531. void    ViewerClip3D (HDC hdc)
  532. {
  533.     short    i;
  534.     
  535.     DisplayViewerFrame3D (hdc, viewer35, WVRED);
  536.     DisplayViewerName3D (hdc, viewer35, WVBLUE, 0);
  537.  
  538.     BeginDoubleBuffer3D (&hdc, viewer35);
  539.     SelectViewer3D (viewer35);
  540.     BrushColor (hdc, WVBLUE);
  541.     for (i = 0; i < 5*demo_type; i ++) {
  542.     ClearViewer3D (hdc, viewer35, WVGRAY);
  543.     NsideStar3D (hdc, 0, 0, 0, 5, 20, 5);
  544.     MoveViewer3D (viewer35, 0, 0, -0.5);
  545.     Rotate3D (6 * i, 'z');
  546.     UpdateBuffer3D (hdc, viewer35);
  547.     }
  548.     EndDoubleBuffer3D (&hdc, viewer35);
  549. }
  550.  
  551. void Flag(HDC hdc)
  552. {
  553.     short    i;
  554.     short    x, y, w, h;
  555.  
  556.     SelectViewer2D (viewer22);
  557.     GetViewport2D (viewer22, &x, &y, &w, &h);
  558.     USFlag (hdc);
  559.     DisplayViewerFrame2D (hdc, viewer22, WVBLACK);
  560.     DisplayViewerName2D (hdc, viewer22, WVBLUE, 1);
  561.     SetViewport2D (viewer22, 350, 230, 60, 30);
  562.     USFlag (hdc);
  563.     DisplayViewerFrame2D (hdc, viewer22, WVBLACK);
  564.     SetViewport2D (viewer22, x, y, w, h);
  565. }
  566.  
  567. void    ViewerReset ()
  568. {
  569.     SetViewerName2D (viewer21, "2D Objects");
  570.     SetViewport2D(viewer21, 10, 10, 100, 100);
  571.     SetWindow2D (viewer21, -10, -10, 10, 10);
  572.     
  573.     SetViewerName2D (viewer22, "U.S. Flag");
  574.     SetViewport2D(viewer22, 10, 10, 400, 217);
  575.     SetWindow2D (viewer22, 0, 0, 1, (float) (13.0 / 24.0));
  576.  
  577.     SetViewerName3D (viewer31, "View Motion");
  578.     SetViewport3D(viewer31, 120, 10, 100, 100);
  579.     SetView3D (viewer31, 100, 100, 100, 0, 0, 0, 0);
  580.     SetPerspective3D (viewer31, 45, 1, 1, 1000);
  581.     
  582.     SetViewerName3D (viewer32, "Object Rotation");
  583.     SetViewport3D(viewer32, 230, 10, 100, 100);
  584.     SetView3D (viewer32, 100, 100, 100, 0, 0, 0, 0);
  585.     SetPerspective3D (viewer32, 45, 1, 1, 1000);
  586.  
  587.     SetViewerName3D (viewer33, "View Zoom");
  588.     SetViewport3D(viewer33, 230, 130, 100, 100);
  589.     SetPolarView3D (viewer33, 1, 1, 0, 20, 75, 45, 0);
  590.     SetPerspective3D (viewer33, 90, 1, 1, 1000);
  591.  
  592.     SetViewerName3D (viewer34, "Ortho Project");
  593.     SetViewport3D(viewer34, 120, 130, 100, 100);
  594.     SetPolarView3D (viewer34, 1, 1, 0, 10, 45, 45, 0);
  595.     SetOrthogonal3D (viewer34, -10, 10, -10, 10, 1, 100);
  596.  
  597.     SetViewerName3D (viewer35, "Depth Clipping");
  598.     SetViewport3D(viewer35, 10, 130, 100, 100);
  599.     SetPolarView3D (viewer35, 1, 1, 0, 20, 75, 45, 0);
  600.     SetPerspective3D (viewer35, 90, 1, 1, 80);
  601. }
  602.  
  603. void    RotateSpring (HDC hdc)
  604. {
  605.     short    i;
  606.  
  607.     DisplayViewerFrame3D (hdc, viewer31, WVBLUE);
  608.     SetViewerName3D(viewer31, "3D Curve");
  609.     BeginDoubleBuffer3D (&hdc, viewer31);
  610.     SelectViewer3D (viewer31);
  611.     Scale3D (20, 20, 20);
  612.     for (i = 0; i < 5*demo_type; i ++) {
  613.     ClearViewer3D (hdc, viewer31, WVGRAY);
  614.     PenColor (hdc, WVRED);
  615.     spring (hdc);
  616.     Translate3D (0.05, 0, 0);
  617.     Rotate3D (-6, 'y');
  618.     PushMatrix3D ();
  619.         PenColor (hdc, WVBLACK);
  620.         BrushColor (hdc, WVRED);
  621.     Rotate3D (6 * i, 'z');
  622.     Translate3D (0, 2, 0);
  623.     Rotate3D (3, 'y');
  624.     Tetrahedron (hdc, 1);
  625.     PushMatrix3D ();
  626.     BrushColor (hdc, WVGREEN);
  627.     Rotate3D (6, 'x');
  628.     Translate3D (0, 0, 2);
  629.     Rotate3D (3 * i, 'z');
  630.     Octahedron (hdc, 1);
  631.     PopMatrix3D ();
  632.     PopMatrix3D ();
  633.     UpdateBuffer3D (hdc, viewer31);
  634.     }
  635.     EndDoubleBuffer3D (&hdc, viewer31);
  636. }
  637.  
  638. void    RotateLogo (HDC hdc)
  639. {
  640.     short    i;
  641.  
  642.     DisplayViewerFrame3D (hdc, viewer32, WVBLUE);
  643.     SelectViewer3D (viewer32);
  644.     BeginDoubleBuffer3D (&hdc, viewer32);
  645.     PenColor (hdc, WVBLUE);
  646.     Scale3D (30, 30, 30);
  647.     for ( i = 0; i < 5*demo_type; i++) {
  648.     ClearViewer3D (hdc, viewer32, WVGRAY);
  649.     logo (hdc);
  650.     Rotate3D (6, 'z');
  651.     UpdateBuffer3D (hdc, viewer32);
  652.     }
  653.     EndDoubleBuffer3D (&hdc, viewer32);
  654. }
  655.  
  656. void    RotateSurface (HDC hdc)
  657. {
  658.     short    i;
  659.  
  660.     DisplayViewerFrame3D (hdc, viewer35, WVBLUE);
  661.     SetViewerName3D(viewer35, "NURBS Surface");
  662.     DisplayViewerName3D(hdc, viewer35, WVBLUE, 0);
  663.     BeginDoubleBuffer3D (&hdc, viewer35);
  664.     SelectViewer3D (viewer35);
  665.     Scale3D (2, 2, 2);
  666.     PenColor (hdc, WVMAGENTA);
  667.     for (i = 0; i < 5*demo_type; i++) {
  668.     ClearViewer3D (hdc, viewer35, WVGRAY);
  669.     NURBSSurface3D (hdc, surf, 4, 4, sknot, tknot, 6, 6);
  670.     Rotate3D (6, 'z');
  671.     Rotate3D (12, 'x');
  672.     Rotate3D (3, 'y');
  673.     UpdateBuffer3D (hdc, viewer35);
  674.     }
  675.     EndDoubleBuffer3D (&hdc, viewer35);
  676. }
  677.  
  678. void    RotateDodecahedron (HDC hdc)
  679. {
  680.     short    i;
  681.  
  682.     DisplayViewerFrame3D (hdc, viewer33, WVRED);
  683.     SetViewerName3D(viewer33, "Dodecahedron");
  684.     DisplayViewerName3D(hdc, viewer33, WVBLUE, 0);
  685.     BeginDoubleBuffer3D (&hdc, viewer33);
  686.     SelectViewer3D (viewer33);
  687.     Scale3D (6, 6, 6);
  688.     BrushColor (hdc, WVBROWN);
  689.     for (i = 0; i < 5*demo_type; i ++) {
  690.     ClearViewer3D (hdc, viewer33, WVGRAY);
  691.     Dodecahedron (hdc, 0.5);
  692.     Translate3D (0, 0.1, 0);
  693.     Rotate3D (6, 'z');
  694.     UpdateBuffer3D (hdc, viewer33);
  695.     }
  696.     EndDoubleBuffer3D (&hdc, viewer33);
  697. }
  698.  
  699. void    RotateIcosahedron (HDC hdc)
  700. {
  701.     short    i;
  702.  
  703.     DisplayViewerFrame3D (hdc, viewer34, WVRED);
  704.     SetViewerName3D(viewer34, "Icosahedron");
  705.     DisplayViewerName3D(hdc, viewer34, WVBLUE, 0);
  706.     BeginDoubleBuffer3D (&hdc, viewer34);
  707.     SelectViewer3D (viewer34);
  708.     Scale3D (3, 3, 3);
  709.     BrushColor (hdc, WVYELLOW);
  710.     for (i = 0; i < 5*demo_type; i ++) {
  711.     ClearViewer3D (hdc, viewer34, WVGRAY);
  712.     Icosahedron (hdc, 1);
  713.     Rotate3D (3, 'y');
  714.     Translate3D (0.1, 0, 0);
  715.     Rotate3D (6, 'z');
  716.     UpdateBuffer3D (hdc, viewer34);
  717.     }
  718.     EndDoubleBuffer3D (&hdc, viewer34);
  719. }
  720.  
  721. void    Heart2D (HDC hdc)
  722. {
  723.     DisplayViewerFrame2D (hdc, viewer21, WVRED);
  724.     SetViewerName2D(viewer21, "2D NURBS curve");
  725.     DisplayViewerName2D (hdc, viewer21, WVBLUE, 0);
  726.     SelectViewer2D (viewer21);
  727.     ClearViewer2D (hdc, viewer21, WVGRAY);
  728.     Scale2D (2, 2);
  729.     heart (hdc);
  730. }
  731.  
  732. void    Display (HDC hdc)
  733. {
  734.         switch (demo_item) {
  735.       case 1:
  736.         Object2D (hdc);
  737.         break;
  738.       case 2:
  739.         ViewerMotion3D (hdc);
  740.         break;
  741.       case 3:
  742.         ObjectMotion3D (hdc);
  743.         break;
  744.       case 4:
  745.         ViewerZoom3D (hdc);
  746.         break;
  747.       case 5:
  748.         OrthoProject3D (hdc);
  749.         break;
  750.       case 6:
  751.         ViewerClip3D (hdc);
  752.         break;
  753.       case 7:
  754.         Heart2D (hdc);
  755.         break;
  756.       case 8:
  757.         RotateSpring (hdc);
  758.         break;
  759.       case 9:
  760.         RotateLogo (hdc);
  761.         break;
  762.       case 10:
  763.         RotateSurface (hdc);
  764.         break;
  765.       case 11:
  766.         RotateDodecahedron (hdc);
  767.         break;
  768.       case 12:
  769.         RotateIcosahedron (hdc);
  770.         break;
  771.       case 13:
  772.         Flag (hdc);
  773.         break;
  774.       default:
  775.         ViewerReset ();
  776.         demo_item = 0;
  777.         break;
  778.     }
  779. }
  780.  
  781. void    ProcessWindowPaint (HWND hwnd)
  782. {
  783.     PAINTSTRUCT    ps;
  784.     HDC        hdc;
  785.  
  786.     hdc = BeginPaint (hwnd, &ps);
  787.     if (demo_flag) {
  788.         Display (hdc);
  789.         if (demo_item == 12) {
  790.         InvalidateRect(hwnd, NULL, TRUE);
  791.     } else if (demo_item) {
  792.         InvalidateRect(hwnd, NULL, FALSE);
  793.         }
  794.         demo_item++;
  795.     }
  796.     EndPaint (hwnd, &ps);
  797. }
  798.  
  799. void    ProcessPrint (void)
  800. {
  801.     HDC        hPr;
  802.     short    x1, y1, x2, y2;
  803.  
  804.     GetViewport2D (viewer22, &x1, &y1, &x2, &y2);
  805.     hPr = GetPrinterDC ();
  806.     if (hPr != NULL) {
  807.     Escape (hPr, STARTDOC, 9, (LPSTR) "Graphics", 0L);
  808.     SetViewport2D (viewer22, 10, 10, 1920, 580);
  809.     SelectViewer2D (viewer22);
  810.     DisplayViewerFrame2D (hPr, viewer22, WVBLACK);
  811.     USFlag (hPr);
  812.     SetViewport2D (viewer22, x1, y1, x2, y2);
  813.     Escape (hPr, NEWFRAME, 0, 0L, 0L);
  814.     Escape (hPr, ENDDOC, 0, 0L, 0L);
  815.     DeleteDC(hPr);
  816.     }
  817. }
  818.  
  819. /****************************************************************************
  820.  
  821.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  822.  
  823.     PURPOSE:  Processes messages
  824.  
  825.     MESSAGES:
  826.  
  827.     WM_COMMAND    - application menu (About dialog box)
  828.     WM_DESTROY    - destroy window
  829.  
  830.     COMMENTS:
  831.  
  832.     To process the IDM_ABOUT message, call MakeProcInstance() to get the
  833.     current instance address of the About() function.  Then call Dialog
  834.     box which will create the box according to the information in your
  835.     vlibdemo.rc file and turn control over to the About() function.    When
  836.     it returns, free the intance address.
  837.  
  838. ****************************************************************************/
  839.  
  840. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  841. HWND hWnd;
  842. unsigned message;
  843. WORD wParam;
  844. LONG lParam;
  845. {
  846.     FARPROC lpProcAbout;
  847.  
  848.     switch (message) {
  849.     case WM_COMMAND:
  850.         switch (wParam) {
  851.           case IDM_EXIT:
  852.         ExitGraphics();
  853.             PostQuitMessage(0);
  854.         break;
  855.           case IDM_ABOUT:
  856.         lpProcAbout = MakeProcInstance (About, hInst);
  857.         DialogBox (hInst, "AboutBox", hWnd, lpProcAbout);
  858.         FreeProcInstance (lpProcAbout);
  859.         break;
  860.           case IDM_STOP:
  861.             demo_flag = 0;
  862.         break;
  863.               case IDM_CONTINUE:
  864.             demo_flag = demo_type;
  865.         if (demo_item == 1)
  866.             InvalidateRect(hWnd, NULL, TRUE);
  867.         else
  868.             InvalidateRect(hWnd, NULL, FALSE);
  869.         break;
  870.           case IDM_SHORT:
  871.         demo_type = 1;
  872.             break;
  873.           case IDM_LONG:
  874.         demo_type = 10;
  875.             break;
  876.           case IDM_PRINT:
  877.         ProcessPrint ();
  878.         break;
  879.           case IDM_HELP:
  880.         demo_flag = 0;
  881.         WinHelp(hWnd, "visualib.hlp", HELP_INDEX, 0);
  882.         break;
  883.           default:
  884.             return (DefWindowProc (hWnd, message, wParam, lParam));
  885.         }
  886.             break;
  887.     case WM_DESTROY:
  888.         ExitGraphics ();
  889.         PostQuitMessage (0);
  890.         break;
  891.  
  892.     case WM_PAINT:
  893.         ProcessWindowPaint (hWnd);
  894.         break;
  895.  
  896.     default:
  897.         return (DefWindowProc(hWnd, message, wParam, lParam));
  898.     }
  899.     return (NULL);
  900. }
  901.  
  902. /****************************************************************************
  903.  
  904.     FUNCTION: About (HWND, unsigned, WORD, LONG)
  905.  
  906.     PURPOSE:  Processes messages for "About" dialog box
  907.  
  908.     MESSAGES:
  909.  
  910.     WM_INITDIALOG - initialize dialog box
  911.     WM_COMMAND    - Input received
  912.  
  913.     COMMENTS:
  914.  
  915.     No initialization is needed for this particular dialog box, but TRUE
  916.     must be returned to Windows.
  917.  
  918.     Wait for user to click on "Ok" button, then close the dialog box.
  919.  
  920. ****************************************************************************/
  921.  
  922. BOOL FAR PASCAL About (hDlg, message, wParam, lParam)
  923. HWND hDlg;
  924. unsigned message;
  925. WORD wParam;
  926. LONG lParam;
  927. {
  928.     switch (message) {
  929.     case WM_INITDIALOG:
  930.         return (TRUE);
  931.  
  932.     case WM_COMMAND:
  933.         if (wParam == IDOK || wParam == IDCANCEL) {
  934.         EndDialog (hDlg, TRUE);
  935.         return (TRUE);
  936.         }
  937.         break;
  938.     }
  939.     return (FALSE);
  940. }
  941.